package com.tedu.assess.service.impl;

import com.tedu.assess.mapper.AssessmentMapper;
import com.tedu.assess.mapper.HealthMapper;
import com.tedu.assess.pojo.dto.HealthParam;
import com.tedu.assess.pojo.dto.HealthQuery;
import com.tedu.assess.pojo.entity.Health;
import com.tedu.assess.pojo.vo.HealthVO;
import com.tedu.assess.service.HealthService;
import com.tedu.user.mapper.UserMapper;
import com.tedu.user.pojo.dto.UserQuery;
import com.tedu.user.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class HealthServiceImpl implements HealthService {
    @Autowired
    HealthMapper healthMapper;
    @Autowired
    AssessmentMapper assessmentMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public void insert(HealthParam healthParam) {
        log.debug("保存评估信息:参数={}", healthParam);
        Health health = new Health();
        BeanUtils.copyProperties(healthParam,health);
        healthMapper.insert(health);
    }

    @Override
    public List<HealthVO> select(HealthQuery healthQuery) {
        log.debug("查询评估信息业务:参数={}", healthQuery);
        List<HealthVO> list = healthMapper.select(healthQuery);
        for (HealthVO healthVO : list) {
            UserQuery userQuery = new UserQuery();
            userQuery.setUsername(healthVO.getUsername());
            List<UserVO> List =userMapper.selectUser(userQuery);
            for(UserVO userVO : List){
                healthVO.setUserId(userVO.getId());
                userQuery.setId(healthVO.getUserId());
                List<UserVO> userVOList = userMapper.selectUser(userQuery);
                healthVO.setUsername(userVOList.get(0).getUsername());
                healthVO.setNum(userVOList.get(0).getNum());
                healthVO.setGender(userVOList.get(0).getGender());
                healthVO.setAge(userVOList.get(0).getAge());
                System.out.println(healthVO);
            }
        }
        return list;
    }

    @Override
    public void delete(Integer id) {
        log.debug("删除评估信息业务:参数={}", id);
        healthMapper.delete(id);
    }
}
